package com.dream.keigezhushou.Activity.Fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;

import com.dream.keigezhushou.Activity.Uiutils.StringUtils;
import com.dream.keigezhushou.Activity.Uiutils.UiUtils;
import com.dream.keigezhushou.Activity.kege.acty.SingingDetailActivity;
import com.dream.keigezhushou.Activity.kege.adapter.MyKeAdapter;
import com.dream.keigezhushou.Activity.kege.adapter.SingRankingAdapter;
import com.dream.keigezhushou.R;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

/**
 * 合唱排行榜
 */
public class SingRankingFragment extends Fragment {
    private PullToRefreshListView mMPullToRefreshListView;
    private ListView mListlv;
    private Intent intent;
    private SingRankingAdapter adapter;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initData();
        //getDataFromService();   获取网络数据并解析
        // 加载动画
        //设置上拉刷新重新请求网络数据  更新adapter?
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mMPullToRefreshListView = (PullToRefreshListView) UiUtils.inflateView(R.layout.kege_fragment);
        mListlv = mMPullToRefreshListView.getRefreshableView();
        initView();
        return mMPullToRefreshListView;
    }

    private void initView() {
        adapter = new SingRankingAdapter(getContext(), 1);
        mListlv.setAdapter(adapter);

        adapter.setItemOnClickListening(new SingRankingAdapter.ItemOnClickListening() {
            @Override
            public void itemClick(int postion) {
                Intent intent = new Intent();
                intent.putExtra(StringUtils.KEGESTATE, "合唱");
                intent.setClass(getContext(), SingingDetailActivity.class);
                startActivity(intent);
            }
        });


    }

    private void initData() {


    }


}


//    public static void setListViewHeightBasedOnChildren(ListView listView) {
//        if(listView == null) return;
//        ListAdapter listAdapter = listView.getAdapter();
//        if (listAdapter == null) {
//            // pre-condition
//            return;
//        }
//        int totalHeight = 0;
//        for (int i = 0; i < listAdapter.getCount(); i++) {
//            View listItem = listAdapter.getView(i, null, listView);
//            listItem.measure(0, 0);
//            totalHeight += listItem.getMeasuredHeight();
//        }
//        ViewGroup.LayoutParams params = listView.getLayoutParams();
//        params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
//        listView.setLayoutParams(params);
//    }




